//
//  ViewController.m
//  15-HomeWork
//
//  Created by 李昊林 on 16/8/3.
//  Copyright © 2016年 李昊林. All rights reserved.
//

#import "ViewController.h"
#import "LHLLayout.h"
#import "LHLCollectionViewCell.h"
#import "SelfSizeTool.h"

@interface ViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,LHLLayoutDelegate>
@property (nonatomic, strong) UICollectionView *collection;
@property (nonatomic, strong) NSMutableArray *dataArr;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    //scrollView自动边距
    //遇到状态栏 ，导航栏，自动为页面上的某一个scrollView添加边距
    //一般在开发中，关闭这个属性
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.navigationBar.translucent = NO;
    LHLLayout *lay = [LHLLayout new];
    lay.delegate = self;
    self.collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 414, 44) collectionViewLayout:lay];
    
    [self.view addSubview:_collection];
    _collection.backgroundColor = [UIColor whiteColor];
    _collection.delegate = self;
    _collection.dataSource = self;
    
    [_collection registerNib:[UINib nibWithNibName:@"LHLCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"1"];
    _dataArr = [NSMutableArray arrayWithObjects:@"头条",@"精选",@"娱乐",@"体育",@"网易号",@"大连",@"视频",@"财经",@"科技",@"汽车",@"时尚",@"图片",@"直播",@"热点",@"跟贴",@"房产",@"轻松一刻",@"段子",@"军事",@"历史",@"家居",@"独家",@"游戏",@"健康",@"政务",@"漫画",@"哒哒趣闻",@"彩漂",@"美女", nil];
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout widthForItemAtIndexPath:(NSIndexPath *)indexPath height:(CGFloat)height {
    return [SelfSizeTool selfSizeWidthWithString:_dataArr[indexPath.row] height:height font:[UIFont systemFontOfSize:17]];
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _dataArr.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    LHLCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"1" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor redColor];
    cell.label.text = _dataArr[indexPath.row];
    cell.label.font = [UIFont systemFontOfSize:17];
//    Size.width = ceilf(newRect.Size.width);
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
